<!---- Creator: Eoly -->
<!---- On 2017/1/10 -->
<!---- Call http://palerock.cn -->


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <title>AngularTest</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            /*border: 0;*/
            -webkit-box-sizing: border-box;
            -moz-box-sizing: border-box;
            box-sizing: border-box;
        }
    </style>
    <script src="../angular.js"></script>
    <script>
        var net = "http://palerock.cn/h5_back";
//        var net = "http://localhost:8080";

        var token = localStorage.getItem("token");

        if (!token) {
            alert("您还没有登录");
            location.href = "登陆简单演示.html";
        }

        var app = angular.module('app', [])
                .config(function ($httpProvider) {
                    //设置请求头附带 token
                    $httpProvider.defaults.headers.common.Authorization = 'Bearer ' + token;
                });

        app.controller('test', function ($scope, $http) {


            $scope.test = function(){
                $http({
                    url:net+'/user/group/show-all-groups',
                    method:'get',
                    params:{}
                }).then(function(res){
                    console.log(res);
                    if(!res.data.error){
                        alert(res.data.mes);
                    }else{
                        alert("错误代码:"+res.data.error+","+res.data.mes)
                    }
                },function(){
                    alert('网络或设置错误');
                });

            }
        });
    </script>
</head>
<body ng-app="app">
<div ng-controller="test" ng-init="test()">
</div>

</body>
</html>